package com.cos.shop.web.controller;

import com.alibaba.fastjson.JSON;
import com.cos.shop.entity.Type;
import com.cos.shop.services.TypeServices;
import com.cos.shop.services.impl.TypeServicesImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author: COS
 * @time: 2022/2/23 14:06
 * @description:
 */
@WebServlet("/type")
public class TypeController extends BaseServlet {
    private TypeServices ts = new TypeServicesImpl();

    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/2/24 8:58
     * @description: 获取所有商品类型
     */
    public String getAll(HttpServletRequest request, HttpServletResponse response){
        //1 访问业务层获取所有商品类型数据
        List<Type>  typeList = ts.getAll();
        //2 list数据转为json的字符串数据响应出去
        String jsonString = JSON.toJSONString(typeList);
        //3 返回
        return jsonString;
    }

}
